﻿using Inovout.Services;
using NHibernate.Criterion;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Inovout.Locations
{
    public class LocationService : RepositoryService<Location>, ILocationService
    {

        public IList<Location> FindByParent(Location location)
        {
            if (location != null)
            {
                return base.Repository.FindAll((Restrictions.Eq("Parent.Id", (object)location.Id)));
            }
            else
            {
                return base.Repository.FindAll((Restrictions.IsNull("Parent.Id")));
            }
           
        }

        public Location FindByName(string key)
        {
            return base.Repository.Find((Restrictions.Eq("Name", key)));
        }
    }
}
